$(document).ready(function() {
		
	// SLIDER MENU RIGHT
	$("#accordion p.menu_accordion_title span").addClass('open');
	//slides the element with class "menu_accordion_body" when paragraph with class "menu_accordion_title" is clicked
	$("#accordion .menu_accordion_title span:eq(0)").click(function () {
		if ($(this).hasClass("open")) {
			$(this).removeClass("open");
			$("#accordion .menu_accordion_body:eq(0)").slideUp(300);
			$(this).html("show");
		} else {
			$(this).addClass("open");
			$("#accordion .menu_accordion_body:eq(0)").slideDown(300);
			$(this).html("hide");
		}
	});
	
	$("#accordion .menu_accordion_title span:eq(1)").click(function () {
		if ($(this).hasClass("open")) {
			$(this).removeClass("open");
			$("#accordion .menu_accordion_body:eq(1)").slideUp(300);
			$(this).html("hide");
		} else {
			$(this).addClass("open");
			$("#accordion .menu_accordion_body:eq(1)").slideDown(300);
			$(this).html("show");
		}
	});
	
	// SLIDER MENU RIGHT CP PROFILE
	$("#accordionProfile p.menu_accordion_title").addClass('close');
	//slides the element with class "menu_accordion_body" when paragraph with class "menu_accordion_title" is clicked 
	$("#accordionProfile p.menu_accordion_title").click(function()
	{	
		var index=$(this).index();
		$(this).removeClass('open').addClass('close').next("div.menu_accordion_body").slideToggle(300,function(){
			if($("div.menu_accordion_body").eq(index/2).css("display")=='none')
			{						
				$(this).prev("#accordion p.menu_accordion_title").removeClass('open').addClass('close');
			} else {
				$(this).prev("#accordion p.menu_accordion_title").removeClass('close').addClass('open');
			}
		});
	});
	
	//SEARCH
	var searchvalue = $("#search input[type='text']").val();
	$("#search input[type='text']").focus(function(){
		if(searchvalue == $(this).val()) {
			$(this).val("");
		}
	});
	$("#search input[type='text']").focusout(function(){
		if($(this).val() == "") {
			$(this).val(searchvalue);
		}
	});

	//LOGIN FORM
	$("#login").click(function() {
		
		var action = $("#loginform").attr('action');
		var form_data = {
			ws_user: $("#ws_user").val(),
			ws_pwd: $("#ws_pwd").val(),
			is_ajax: 1
		};
		
		$.ajax({
			type: "POST",
			url: action,
			data: form_data,
			success: function(response)
			{	
				if(response == 'NO')
				$("#message").html("<p class='error'>Invalid username and/or password.</p>");	
				else
					$("#loginform").slideUp('slow', function() {
						$("#header-right").css("display", "none");
						$("#loggedarea").html(response);
					});
			}
		});
		
		return false;
	});
	
	//MENU 
	function alterstate(classer, bol){	
		if(bol){
			$("."+classer).addClass("active");
		}else{
			$("."+classer).removeClass("active");
		}
	}
	
   	$(".menu").click(function(){
		var classes = $(this).attr("class");
		
		$(".menu").each(function(){
			var allclasses = $(this).attr("class");
			if(classes!=allclasses){
				var allclass_array = new Array();
				allclass_array = allclasses.split(" ");
				allclasser = allclass_array[1];
				alterstate(allclasser, false);
			}
		});
		
		
		var class_array = new Array();
		class_array = classes.split(" ");
		classer = class_array[1];
		alterstate(classer, true);	
	});
	
	alterstate("home", true);
	
});